package com.hjy.config;

import com.hjy.properties.HjySecurityProperties;
import com.hjy.utils.TokenManager;
import com.hjy.utils.UserDetailHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;

@Configuration
@EnableConfigurationProperties(HjySecurityProperties.class)
public class HjySecurityAutoConfiguration {

    @Autowired
    private HjySecurityProperties hjySecurityProperties;
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private UserDetailHandler userDetailHandler;

    @Bean
    public TokenManager tokenManager() {
        TokenManager tokenManager = new TokenManager();
        tokenManager.setSecretKey(hjySecurityProperties.getSecretKey());
        return tokenManager;
    }

    @Bean
    public MVConfig mvConfig() {
        return new MVConfig(userDetailHandler,tokenManager(),stringRedisTemplate,hjySecurityProperties);
    }

}
